package lambda;

import org.junit.Test;

import java.util.*;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class LambdaTest {

    //生成指定个数的整数
    public static List<Integer> getNumList(int num, Supplier<Integer> sup) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            list.add(sup.get());
        }
        return list;


    }
    public static void main(String[] args) {
        List<Integer> list = getNumList(3, () -> {
            Random random = new Random();
            int i = random.nextInt(100);
            System.out.println("产生整数:" + i);
            return i;
        });
        System.out.println(list);
        int num =10;
        Runnable  runnable =()->  System.out.println(num);

        Runnable runnable1 = new Thread() {
            @Override
            public void run() {
               System.out.println(num);
            }
        };
        ((Thread) runnable1).start();



//        startThread threadss =()-> System.out.println("22");
        Thread thread =new Thread();



        Consumer<String> com = (x) -> System.out.println(x);
//        com.accept("Hello World!");

        Consumer<Object> consumer =new Consumer<Object>() {
            @Override
            public void accept(Object o) {
                o=o.toString()+"dasdasd";
            }
        };

        consumer.accept("sbbbb");

//        //匿名内部类
//        Comparator<Integer> com = new Comparator<Integer>() {
//            @Override
//            public int compare(Integer o1, Integer o2) {
//                return Integer.compare(o1,o2);
//            }
//        };
//
//        Comparator<Integer>comparators =(x,y)-> Integer.compare(x,y);

        BinaryOperator<Integer> bi = (x, y) -> {
            System.out.println("加法");
            return x + y;
        };
        Integer apply = bi.apply(23, 45);

        System.out.println(apply);




    }


    @Test
    public void test3() {
        String name = "Hello";
        String converString = funcation(name, (x) -> x + UUID.randomUUID().toString().replace("-", ""));
        System.out.println(converString);
    }

    //对字符串处理
    public String funcation(String str, Function<String, String> fun) {
        return fun.apply(str);
    }



}